package com.posjiajia.user.operator.controller;

import com.posjiajia.commom.utils.vo.result.BaseResult;
import com.posjiajia.commom.utils.vo.result.DataResult;
import com.posjiajia.user.core.bo.OrganBo;
import com.posjiajia.user.core.params.OrganQueryParam;
import com.posjiajia.user.core.vo.OrganVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zhenhua.sun
 * @title com.posjiajia.user.operator.controller
 * @date 8/30/16
 */
@Controller
@RequestMapping("/organ")
public class OrganController {

    @Autowired
    private OrganBo organBo;

    @RequestMapping("/post")
    @ResponseBody
    public BaseResult postOrgan(OrganVo organVo){
        if (organVo.getOrganId() != null){
            organBo.update(organVo);
        }else {
            organBo.insert(organVo);
        }
        return BaseResult.SUCCESS;
    }

    @RequestMapping("/query")
    @ResponseBody
    public DataResult query(OrganQueryParam organQueryParam){
        List<OrganVo> voList = organBo.query(organQueryParam);
        DataResult dataResult = new DataResult();
        dataResult.setData(voList);
        return dataResult;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String query(){
        return "organ/organList";
    }
}